<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>main</title>
    <link rel="stylesheet" type="text/css" href="{{$smarty.const.JS}}layui/css/layui.css" />
    <style>
        form {margin-top: 20px;}
    </style>
    <script type="text/javascript" src="{{$smarty.const.JS}}forbidRight.js"></script>
</head>

<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <!-- <label class="layui-form-label">选择可操作菜单</label> -->
            <div class="layui-input-block">
            {{foreach $item as $v}}
                <input type="checkbox" name="nav_ids[]" lay-filter="nav" value="{{$v.id}}" title="{{$v.name}}" {{if $v.check==1}} checked{{/if}}>
            {{/foreach}}
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="edit">确认修改</button>
            </div>
        </div>
    </form>
    <script src="{{$smarty.const.JS}}layui/layui.js" charset="utf-8"></script>
    <script>
    layui.use(['table','form'], function() {
        var $ = layui.$,
            form = layui.form;

        //复选框选择
        form.on('checkbox(nav)', function(obj){
            console.log(obj);
        });

        form.on('submit(edit)', function(){
            var nav = "";
            var flag = "";
            var ids = "";
            $("input[type='checkbox']:checked").each(function() { // 遍历name=test的多选框
                ids += flag + $(this).val();  // 每一个被选中项的值
                flag = ",";
            });
            // console.log(ids);
            var id = {{$smarty.get.id}};
            $.ajax({
                url:'edit',
                data:{ids:ids,id:id},
                type:'post',
                dataType:'json',
                success:function(redata){
                    if (redata.msg == 1) {
                        window.parent.parent.location.reload();//刷新父页面
                        layer.closeAll('iframe');//关闭弹窗
                    }else if(redata.msg == 2){
                        layer.alert("修改失败，请重试！");
                        layer.closeAll('iframe');//关闭弹窗
                    }
                }
            });
            return false;
        });    
    });
    </script>
</body>

</html>